package cn.kgc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        Object user = request.getSession().getAttribute("kgcUser");
        if (user==null){
                response.sendRedirect(request.getContextPath()+"/login");
            return  false;
        }
        return true;
    }
}
